﻿using System;
using System.Web;
using System.Reflection;

namespace FreeHouse.Shop
{
    /// <summary>
    ///Util 的摘要说明   fgf
    /// </summary>
    public class Util
    {
      
        /// <summary>
        /// 设置cookie
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public static void SetCookie(string key, string value)
        {
            HttpCookie hc = new HttpCookie(key);
            hc.Value = value;
            hc.Expires = DateTime.Now.AddHours(5);
            System.Web.HttpContext.Current.Response.Cookies.Add(hc);
        }
        /// <summary>
        /// 获取某个cookie 值
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetCookie(string key)
        {
            HttpCookie hc = System.Web.HttpContext.Current.Request.Cookies[key];
            if (hc == null)
                return null;
            else
                return hc.Value;
        }
        /// <summary>
        /// 将某个cookie 设为过期
        /// </summary>
        /// <param name="name"></param>
        public static void ClearCookie(string key)
        {
            HttpCookie hc = System.Web.HttpContext.Current.Request.Cookies[key];
            if (hc != null)
            {
                hc.Expires = DateTime.Now.AddDays(-1);
                System.Web.HttpContext.Current.Response.Cookies.Add(hc);
            }
        }

        /// <summary>
        /// cookie 是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool ExistCookie(string key)
        {
            HttpCookie hc = System.Web.HttpContext.Current.Request.Cookies[key];
            return hc != null;
        }

        /// <summary>
        /// 替换掉引号
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ClearYinHao(string value)
        {
            return value.Replace("\"", "").Replace("'", "");
        }
        /// <summary>
        /// 加载门店活动所需控件程序集
        /// </summary>
        
        public static void Die(HttpContext content, string msg)
        {
            content.Response.Write(msg);
            content.Response.End();
        }
        /// <summary>
        /// 返回js标签,不用填写script代码块
        /// </summary>
        /// <param name="js"></param>
        /// <returns></returns>
        public static string PrintScript(string js)
        {
            return "<script type='text/javascript'>"+js+"</script>";
        }
        
    }
   
}